package main

import (
	"cserver/api/exlog"
	"cserver/app"
	"fmt"
	"github.com/fsnotify/fsnotify"
	"github.com/spf13/viper"
	"log"
)

var (
	//ROOT   = "/Users/switch/go/src/cserver" //根目录
	ROOT   = "/Users/switch/go/src/cserver"
	addr   = "0.0.0.0:7777"
	wsPath = "/ws"
	err    error
)

/*
 * 交叉编译
 * 编译linux   CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go
 * 编译windows CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go
 */
func main() {
	//开启配置文件
	viper.SetDefault("ROOT", ROOT)
	viper.SetDefault("ROOT", ROOT)
	viper.SetDefault("LOGPATH", ROOT+"/log/")
	viper.SetConfigName("cserver.yaml")
	viper.AddConfigPath(ROOT + "/etc/")
	if err = viper.ReadInConfig(); err != nil {
		log.Panic(err)
	}
	//开启日志
	exlog.InitLog()
	//监听配置文件改变
	viper.WatchConfig()
	viper.OnConfigChange(func(e fsnotify.Event) {
		fmt.Println("Config file changed:", e.Name)
	})

	//开启websocket监听
	app.HttpStart(addr, wsPath)
}
